<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数码闹钟</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 1000px;
            height: 400px;
            background: cyan;
            margin: 100px auto;
            padding: 0 50px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 50px;
        }
        img {
            width: 18%;
            height: 75%;
        }
    </style>
</head>

<body>
    <div id="box">
            <img src="./img/0.png" alt="">
            <img src="./img/0.png" alt="">
            :
            <img src="./img/0.png" alt="">
            <img src="./img/0.png" alt="">
            :
            <img src="./img/0.png" alt="">
            <img src="./img/0.png" alt="">
    </div>

    <script>
        window.onload = function(){
            // 判断是否为单数，是就 在前面拼接个0
            function toDouble(num){
                if(num < 10){
                    return '0' + num;
                }else{
                    return '' + num;
                }
            }
            //拿出img的标签 
            var imgUrl = document.getElementsByTagName('img')

            setInterval(function(){
                var data = new Date()
                // 时
                var h = data.getHours()
                // 分
                var m = data.getMinutes()
                // 秒
                var s = data.getSeconds()

                var str = toDouble(h)+toDouble(m)+toDouble(s)

                for(var i = 0; i < imgUrl.length; i++){
                    imgUrl[i].src = './img/'+ str[i] +'.png'
                }

            },1000)
            
            
        }
    </script>
</body>

</html>